﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace test_fichiers.ViewModels
{
	public class FilesViewModel : INotifyPropertyChanged
	{
		ObservableCollection<Models.FilesModel> m_files;
		Models.FilesModel m_currentFile;

		public ObservableCollection<Models.FilesModel> Files
        {
            get { return (m_files); }
            set
            {
                if (m_files != value)
                {
                    m_files = value;
                    OnPropertyChanged("Files");
                }
            }
        }
		public Models.FilesModel CurrentFile
		{
			get { return (m_currentFile); }
			set
			{
				if (m_currentFile != value)
				{
					m_currentFile = value;
					OnPropertyChanged("CurrentFile");
				}
			}
		}
		public ICommand CommandSave
		{
			get { return (new SaveFileComand(this)); }
		}

		public FilesViewModel()
		{
			m_files = new ObservableCollection<Models.FilesModel>();
			m_files.Add(new Models.FilesModel("./toto.exe", "toto", "exe"));
			m_files.Add(new Models.FilesModel("./tata.exe", "tata", "exe"));
			m_files.Add(new Models.FilesModel("./tutu.exe", "tutu", "exe"));
		}

		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string _name)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(_name));
        }

        #endregion
	}

	public class SaveFileComand : ICommand
	{
		FilesViewModel m_files;

		public event EventHandler CanExecuteChanged;

		public SaveFileComand(FilesViewModel _files)
		{
			m_files = _files;
		}

		public bool CanExecute(object _parameter)
		{
			return (_parameter != null);
		}

		public void Execute(object _parameter)
		{
			m_files.CurrentFile = _parameter as Models.FilesModel;
		}
	}
}
